import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSetMetaData;

class DB
{
    private static String dbURL = "jdbc:derby://localhost:1527/NavalBattle;create=false;user=denis;password=qazxswed";
    private static String tableName = "restaurants";
    // jdbc Connection
    private static Connection conn = null;
    private static Statement stmt = null;
    private static DB instance;

    public DB ()
    {
	createConnection();
    }	
    
    public static DB getInstance()
    {
        if (instance == null)
        {
            instance = new DB();
        }
        
        return instance;
    }

    private void createConnection()
    {
        try
        {
            Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
            //Get a connection
            conn = DriverManager.getConnection(dbURL); 
        }
        catch (Exception except)
        {
            except.printStackTrace();
        }
    }
	
    private void insert()
    {
	try
        {
            stmt = conn.createStatement();
            stmt.execute("insert into Battles (id, duration, turns, player1_id, player2_id, winner_id) values (1, 15, 30, 1, 2, 1)");
            stmt.close();
        }
        catch (SQLException sqlExcept)
        {
            sqlExcept.printStackTrace();
        }
    }
}